term == "exp1sovereignty" ~ "Foreign\nSovereignty")) %>%
mutate(model = "Would you support or oppose this new trade agreement with [Partner]?")
cplot21
cplot22 <- broom::tidy(mod2a, conf.int = TRUE, conf.level = 0.95)%>%
mutate(exp1 = case_when(term == "exp1protectionism" ~ "US Economic\nCosts",
term == "exp1sovereignty" ~ "Foreign\nSovereignty")) %>%
mutate(model = "Is this new trade agreement fair or unfair for the United States?")
cplot22
cplot23 <- broom::tidy(mod3a, conf.int = TRUE, conf.level = 0.95)%>%
mutate(exp1 = case_when(term == "exp1protectionism" ~ "US Economic\nCosts",
term == "exp1sovereignty" ~ "Foreign\nSovereignty")) %>%
mutate(model = "Is this new trade agreement fair or unfair for [Partner]?")
cplot23
cplot2_combo <- rbind(cplot21, cplot22, cplot23) %>%
drop_na(exp1) %>%
mutate(model = fct_relevel(model,
"Would you support or oppose this new trade agreement with [Partner]?",
"Is this new trade agreement fair or unfair for the United States?",
"Is this new trade agreement fair or unfair for [Partner]?"))
plot_cplot2 <- ggplot(cplot2_combo, aes(x = estimate, xmin = conf.low, xmax = conf.high, y = exp1)) +
geom_vline(xintercept = 0, colour = "indianred", lty = "dashed") +
geom_point(size = 3) +
geom_linerange(size = 1) +
scale_x_continuous(limits = c(-0.3, 0.3)) +
facet_wrap(~model, ncol = 1) +
theme_bw() +
theme(
strip.background = element_rect(fill = "#F3F4F9"),
strip.text = element_text(face = "bold")
) +
labs(
x = "Estimate",
y = ""
)
plot_cplot2
ggsave(filename = here("2 Figures", "Experiment 2 (Frames) Coefficient Plot (Presentation).png"), plot = plot_cplot2, scale = 1.1)
plot_cplot2_paper <- ggplot(cplot2_combo, aes(x = estimate, xmin = conf.low, xmax = conf.high, y = exp1)) +
geom_vline(xintercept = 0, colour = "indianred", lty = "dashed") +
geom_point(size = 3) +
geom_linerange(size = 1) +
scale_x_continuous(limits = c(-0.3, 0.3)) +
scale_y_discrete(labels = c("US Economic\nCosts" = "Digital Protectionism", "Foreign\nSovereignty"="Digital Sovereignty")) +
facet_wrap(~model, ncol = 1) +
theme_bw() +
theme(
strip.background = element_rect(fill = "#F3F4F9"),
strip.text = element_text(face = "bold")
) +
labs(
x = "Estimate",
y = ""
)
plot_cplot2_paper
ggsave(filename = here("2 Figures", "Experiment 2 (Frames) Coefficient Plot (Paper).png"), plot = plot_cplot2_paper, scale = 1.1)
#### ~~~ Coef Plot Partner ~~~ ####
cplot31 <- broom::tidy(mod1b, conf.int = TRUE, conf.level = 0.95)%>%
mutate(exp2 = case_when(term == "exp2china" ~ "China",
term == "exp2south korea" ~ "South Korea")) %>%
mutate(model = "Would you support or oppose this new trade agreement with [Partner]?")
cplot31
cplot32 <- broom::tidy(mod2b, conf.int = TRUE, conf.level = 0.95)%>%
mutate(exp2 = case_when(term == "exp2china" ~ "China",
term == "exp2south korea" ~ "South Korea")) %>%
mutate(model = "Is this new trade agreement fair or unfair for the United States?")
cplot32
cplot33 <- broom::tidy(mod3b, conf.int = TRUE, conf.level = 0.95)%>%
mutate(exp2 = case_when(term == "exp2china" ~ "China",
term == "exp2south korea" ~ "South Korea")) %>%
mutate(model = "Is this new trade agreement fair or unfair for [Partner]?")
cplot33
cplot3_combo <- rbind(cplot31, cplot32, cplot33) %>%
drop_na(exp2) %>%
mutate(model = fct_relevel(model,
"Would you support or oppose this new trade agreement with [Partner]?",
"Is this new trade agreement fair or unfair for the United States?",
"Is this new trade agreement fair or unfair for [Partner]?"))
plot_cplot3 <- ggplot(cplot3_combo, aes(x = estimate, xmin = conf.low, xmax = conf.high, y = exp2)) +
geom_vline(xintercept = 0, colour = "indianred", lty = "dashed") +
geom_point(size = 3) +
geom_linerange(size = 1) +
scale_x_continuous(limits = c(-0.6, 0.2)) +
facet_wrap(~model, ncol = 1) +
theme_bw() +
theme(
strip.background = element_rect(fill = "#F3F4F9"),
strip.text = element_text(face = "bold")
) +
labs(
x = "Estimate",
y = ""
)
plot_cplot3
ggsave(filename = here("2 Figures", "Experiment 2 (Partner) Coefficient Plot (Presentation).png"), plot = plot_cplot3, scale = 1.1)
plot_cplot3_paper <- ggplot(cplot3_combo, aes(x = estimate, xmin = conf.low, xmax = conf.high, y = exp2)) +
geom_vline(xintercept = 0, colour = "indianred", lty = "dashed") +
geom_point(size = 3) +
geom_linerange(size = 1) +
scale_x_continuous(limits = c(-0.6, 0.2)) +
facet_wrap(~model, ncol = 1) +
theme_bw() +
theme(
strip.background = element_rect(fill = "#F3F4F9"),
strip.text = element_text(face = "bold")
) +
labs(
x = "Estimate",
y = ""
)
plot_cplot3_paper
ggsave(filename = here("2 Figures", "Experiment 2 (Partner) Coefficient Plot (Paper).png"), plot = plot_cplot3, scale = 1.1)
#### ~~~~ Combo Plot ~~~~ ####
cplot2_combo <- rbind(cplot21, cplot22, cplot23) %>%
drop_na(exp1) %>%
mutate(model = case_when(model == "Would you support or oppose this new trade agreement with [Partner]?" ~ "Would you support or oppose this new \ntrade agreement with [Partner]?",
model == "Is this new trade agreement fair or unfair for the United States?" ~ "Is this new trade agreement fair or unfair \nfor the United States?",
model == "Is this new trade agreement fair or unfair for [Partner]?" ~ "Is this new trade agreement fair or unfair \nfor [Partner]?")) %>%
mutate(model = fct_relevel(model,
"Would you support or oppose this new \ntrade agreement with [Partner]?",
"Is this new trade agreement fair or unfair \nfor the United States?",
"Is this new trade agreement fair or unfair \nfor [Partner]?"))
plot_cplot2_paper <- ggplot(cplot2_combo, aes(x = estimate, xmin = conf.low, xmax = conf.high, y = exp1)) +
geom_vline(xintercept = 0, colour = "indianred", lty = "dashed") +
geom_point(size = 3) +
geom_linerange(size = 1) +
scale_x_continuous(limits = c(-0.3, 0.3)) +
scale_y_discrete(labels = c("US Economic\nCosts" = "Digital Protectionism", "Foreign\nSovereignty"="Digital Sovereignty")) +
facet_wrap(~model, ncol = 1) +
theme_bw() +
theme(
strip.background = element_rect(fill = "#F3F4F9"),
strip.text = element_text(face = "bold")
) +
labs(
x = "Estimate",
y = ""
)
plot_cplot2_paper
###
cplot3_combo <- rbind(cplot31, cplot32, cplot33) %>%
drop_na(exp2) %>%
mutate(model = case_when(model == "Would you support or oppose this new trade agreement with [Partner]?" ~ "Would you support or oppose this new \ntrade agreement with [Partner]?",
model == "Is this new trade agreement fair or unfair for the United States?" ~ "Is this new trade agreement fair or unfair \nfor the United States?",
model == "Is this new trade agreement fair or unfair for [Partner]?" ~ "Is this new trade agreement fair or unfair \nfor [Partner]?")) %>%
mutate(model = fct_relevel(model,
"Would you support or oppose this new \ntrade agreement with [Partner]?",
"Is this new trade agreement fair or unfair \nfor the United States?",
"Is this new trade agreement fair or unfair \nfor [Partner]?"))
plot_cplot3_paper <- ggplot(cplot3_combo, aes(x = estimate, xmin = conf.low, xmax = conf.high, y = exp2)) +
geom_vline(xintercept = 0, colour = "indianred", lty = "dashed") +
geom_point(size = 3) +
geom_linerange(size = 1) +
scale_x_continuous(limits = c(-0.6, 0.2)) +
facet_wrap(~model, ncol = 1) +
theme_bw() +
theme(
strip.background = element_rect(fill = "#F3F4F9"),
strip.text = element_text(face = "bold")
) +
labs(
x = "Estimate",
y = ""
)
plot_cplot3_paper
###
cplot_combo_paper <- ggpubr::ggarrange(plot_cplot2_paper, plot_cplot3_paper,
nrow = 1,
labels = "AUTO")
ggsave(filename = here("2 Figures", "Experiment 2 Main Effects Coefficient Plot (Paper).png"), plot = cplot_combo_paper, scale = 1.1)
#### ~~~ Marginal Effects Crossed ~~~ ####
## Question 1
plotint1paper <- plot_predictions(mod1c, by = c("exp2", "exp1"), conf_level = 0.95, draw = FALSE) %>%
mutate(exp1 = case_when(exp1 == "control" ~ "Control",
exp1 == "protectionism" ~ "Digital\nProtectionism",
exp1 == "sovereignty" ~ "Digital\nSovereignty")) %>%
mutate(exp2 = case_when(exp2 == "canada" ~ "Canada",
exp2 == "china" ~ "China",
exp2 == "south korea" ~ "South Korea"))
plotint1paper <- ggplot(plotint1paper, aes(x = exp2, y = estimate, ymin = conf.low, ymax = conf.high)) +
geom_pointrange(aes(color = exp1, shape = exp1), stat = "identity", position = position_dodge2(width = .5), size = 0.5) +
scale_y_continuous(limits = c(-0.1, 1)) +
scale_color_manual(values = c("black", "#d55e00", "#0072b2")) +
labs(
x = "",
y = "Predicted Value",
title = "Would you support or oppose this new trade agreement with [Partner]?"
) +
theme_minimal() +
theme(
legend.title = element_blank(),
legend.position = "bottom"
)
plotint1paper
## Question 2
plotint2paper <- plot_predictions(mod2c, by = c("exp2", "exp1"), conf_level = 0.95, draw = FALSE) %>%
mutate(exp1 = case_when(exp1 == "control" ~ "Control",
exp1 == "protectionism" ~ "Digital\nProtectionism",
exp1 == "sovereignty" ~ "Digital\nSovereignty")) %>%
mutate(exp2 = case_when(exp2 == "canada" ~ "Canada",
exp2 == "china" ~ "China",
exp2 == "south korea" ~ "South Korea"))
plotint2paper <- ggplot(plotint2paper, aes(x = exp2, y = estimate, ymin = conf.low, ymax = conf.high)) +
geom_pointrange(aes(color = exp1, shape = exp1), stat = "identity", position = position_dodge2(width = .5), size = 0.5) +
scale_y_continuous(limits = c(-0.1, 1)) +
scale_color_manual(values = c("black", "#d55e00", "#0072b2")) +
labs(
x = "",
y = "Predicted Value",
title = "Is this new trade agreement fair or unfair for the United States?"
) +
theme_minimal() +
theme(
legend.title = element_blank(),
legend.position = "bottom"
)
plotint2paper
## Question 3
plotint3paper <- plot_predictions(mod3c, by = c("exp2", "exp1"), conf_level = 0.95, draw = FALSE) %>%
mutate(exp1 = case_when(exp1 == "control" ~ "Control",
exp1 == "protectionism" ~ "Digital\nProtectionism",
exp1 == "sovereignty" ~ "Digital\nSovereignty")) %>%
mutate(exp2 = case_when(exp2 == "canada" ~ "Canada",
exp2 == "china" ~ "China",
exp2 == "south korea" ~ "South Korea"))
plotint3paper <- ggplot(plotint3paper, aes(x = exp2, y = estimate, ymin = conf.low, ymax = conf.high)) +
geom_pointrange(aes(color = exp1, shape = exp1), stat = "identity", position = position_dodge2(width = .5), size = 0.5) +
scale_y_continuous(limits = c(-0.1, 1)) +
scale_color_manual(values = c("black", "#d55e00", "#0072b2")) +
labs(
x = "",
y = "Predicted Value",
title = "Is this new trade agreement fair or unfair for [Partner]?"
) +
theme_minimal() +
theme(
legend.title = element_blank(),
legend.position = "bottom"
)
plotint3paper
plotint_combo <- ggarrange(plotint1paper, plotint2paper, plotint3paper,
ncol = 1,
common.legend = TRUE,
legend = "bottom")
ggsave(filename = here("2 Figures", "Experiment 2 (Crossed) Effects Plot - All Questions (Paper).png"), plot = plotint_combo, scale = 1.1)
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#### ~ Tables ~ ####
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
## Q1
modsac <- list(
mod1a,
mod1a_completedata,
mod1b,
mod1b_completedata,
mod1c,
mod1c_completedata
)
cm <- c(
'(Intercept)'='Intercept',
'exp1protectionism'='Digital Protectionism',
'exp1sovereignty'='Digital Sovereignty',
'exp2china'='China',
'exp2south korea'='South Korea',
'exp1protectionism:exp2china'='Digital Protectionism x China',
'exp1sovereignty:exp2china'='Digital Sovereignty x China',
'exp1protectionism:exp2south korea'='Digital Protectionism x South Korea',
'exp1sovereignty:exp2south korea'='Digital Sovereignty x South Korea'
)
rows <- tribble(~term,          ~"(1)",  ~"(2)", ~"(3)",  ~"(4)", ~"(5)",  ~"(6)",
'Attention Check',         'Pass', 'All','Pass', 'All','Pass', 'All')
attr(rows, 'position') <- c(11)
tab <- modelsummary(modsac,
output = "gt",
stars = TRUE,
coef_map = cm,
estimate = "{estimate} ({std.error}){stars}",
statistic = NULL,
add_rows = rows,
gof_map = c("nobs", "r.squared"))
tab
gt::gtsave(tab, filename = here("3 Tables", "Experiment 2 Table 1.docx"))
## Q2
modsac <- list(
mod2a,
mod2a_completedata,
mod2b,
mod2b_completedata,
mod2c,
mod2c_completedata
)
cm <- c(
'(Intercept)'='Intercept',
'exp1protectionism'='Digital Protectionism',
'exp1sovereignty'='Digital Sovereignty',
'exp2china'='China',
'exp2south korea'='South Korea',
'exp1protectionism:exp2china'='Digital Protectionism x China',
'exp1sovereignty:exp2china'='Digital Sovereignty x China',
'exp1protectionism:exp2south korea'='Digital Protectionism x South Korea',
'exp1sovereignty:exp2south korea'='Digital Sovereignty x South Korea'
)
rows <- tribble(~term,          ~"(1)",  ~"(2)", ~"(3)",  ~"(4)", ~"(5)",  ~"(6)",
'Attention Check',         'Pass', 'All','Pass', 'All','Pass', 'All')
attr(rows, 'position') <- c(11)
tab <- modelsummary(modsac,
output = "gt",
stars = TRUE,
coef_map = cm,
estimate = "{estimate} ({std.error}){stars}",
statistic = NULL,
add_rows = rows,
gof_map = c("nobs", "r.squared"))
tab
gt::gtsave(tab, filename = here("3 Tables", "Experiment 2 Table 2.docx"))
## Q3
modsac <- list(
mod3a,
mod3a_completedata,
mod3b,
mod3b_completedata,
mod3c,
mod3c_completedata
)
cm <- c(
'(Intercept)'='Intercept',
'exp1protectionism'='Digital Protectionism',
'exp1sovereignty'='Digital Sovereignty',
'exp2china'='China',
'exp2south korea'='South Korea',
'exp1protectionism:exp2china'='Digital Protectionism x China',
'exp1sovereignty:exp2china'='Digital Sovereignty x China',
'exp1protectionism:exp2south korea'='Digital Protectionism x South Korea',
'exp1sovereignty:exp2south korea'='Digital Sovereignty x South Korea'
)
rows <- tribble(~term,          ~"(1)",  ~"(2)", ~"(3)",  ~"(4)", ~"(5)",  ~"(6)",
'Attention Check',         'Pass', 'All','Pass', 'All','Pass', 'All')
attr(rows, 'position') <- c(11)
tab <- modelsummary(modsac,
output = "gt",
stars = TRUE,
coef_map = cm,
estimate = "{estimate} ({std.error}){stars}",
statistic = NULL,
add_rows = rows,
gof_map = c("nobs", "r.squared"))
tab
gt::gtsave(tab, filename = here("3 Tables", "Experiment 2 Table 3.docx"))
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#### ~ Contrasts ~ ####
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
avg_comparisons(
mod1c,
variables = "exp1",
by = "exp2"
)
# note: this is cited in the main text (Section 5: Results)
# protectionism - control (Canada) = -0.1972 (p = 0.0246)
# sovereignty - control (China) = 0.1557 (p = 0.0765)
avg_comparisons(
mod2c,
variables = "exp1",
by = "exp2"
)
# note: this is cited in the main text (Section 5: Results)
# protectionism - control (Canada) = -0.16213 (p = 0.05899)
# sovereignty - control (China) = 0.22308 (p = 0.00952)
avg_comparisons(
mod3c,
variables = "exp1",
by = "exp2"
)
###
#
# Data Localization Project
#
# Trade Agreements Map
#
# Authors: Tyler Girard and Alex Wilhelm
#
#
#
###
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#### Load Packages ####
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
library(here)
library(tidyverse)
library(rio)
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#### Set Seed ####
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
set.seed(515)
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#### Load Data ####
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
df <- import(here("1 Data", "TAPED_Dataset_Burri_Vasquez_Kugler_November_2022.xlsx"))
head(df)
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#### Prep Data ####
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
pdat <- df %>%
select(taped_number, long_title, short_title, type, type_memb, parties, year_in_force,
digchap=data_flo_lim_proh_loc_2_3_3, outchap=data_flow_proh_loc_2_2_3) %>%
mutate(year_in_force = na_if(year_in_force, "N/A")) %>%
mutate(digchap = na_if(digchap, "N/A")) %>%
mutate(year_in_force = na_if(year_in_force, "0")) %>%
drop_na(year_in_force) %>%
mutate(digchap = as.numeric(digchap)) %>%
mutate(ex = case_when(digchap == 0 & outchap == 0 ~ 0,
TRUE ~ 1)) %>%
filter(ex == 1)
head(pdat)
summary(pdat)
test <- pdat$parties
ls <- list()
for(i in 1:length(test)){
ls[[i]] <- str_extract_all(test[i], "\\b[a-zA-Z]{3}\\b")[[1]]
}
newls <- sort(unique(unlist(ls)))
# create data for world coordinates using
# map_data() function
world_coordinates <- map_data("world")
world_coordinates <- world_coordinates %>%
mutate(tradeagreement = case_when(region == "Argentina" |
region == "Australia" |
region == "Brazil" |
region == "Brunei" |
region == "Canada" |
region == "Chile" |
region == "China" |
region == "Colombia" |
region == "UK" |
region == "Indonesia" |
region == "Japan" |
region == "Cambodia" |
region == "South Korea" |
region == "Laos" |
region == "Sri Lanka" |
region == "Mexico" |
region == "Mongolia" |
region == "Malaysia" |
region == "New Zealand" |
region == "Peru" |
region == "Philippines" |
region == "Singapore" |
region == "Thailand" |
region == "Uruguay" |
region == "USA" |
region == "Vietnam" |
# rest of ASEAN
region == "Myanmar" |
region == "Malaysia" ~ "Yes",
TRUE ~ "No")) %>%
filter(region != "Antarctica")
head(world_coordinates)
# create world map using ggplot() function
ggplot() +
# geom_map() function takes world coordinates as input
# to plot world map color parameter determines the
# color of borders in map fill parameter determines
# the color of fill in map size determines the thickness
# of border in map
geom_map(
data = world_coordinates, map = world_coordinates,
aes(long, lat, map_id = region, fill = tradeagreement),
color = "black", size = 0.2
)
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#### Final Map for Paper ####
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
datalocalmap <- ggplot(world_coordinates, aes(long, lat, group = group)) +
coord_fixed(1.3)+
geom_polygon(aes(fill = tradeagreement), color = "black") +
scale_fill_manual(values = c("lightgrey", "royalblue")) +
theme_minimal() +
theme (panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) +
theme(axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
rect = element_blank()) +
theme (legend.position = "bottom",
legend.title = element_text(color = "black", size=10, family = "sans"),
legend.text = element_text (color = "black", size =8, family = "sans"),
legend.key.size = unit(0.3, 'cm'),
legend.key.height = unit(0.3, 'cm'),
legend.key.width = unit(0.3, 'cm'),
)+
labs(
x = "",
y = "",
fill = "Party to Trade Agreement with Restriction on Use of Data Localization Policies"
)
datalocalmap
ggsave(datalocalmap, filename = here("2 Figures", "Data Localization Trade Agreements Map.png"), scale = 1)
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#### End of Script ####
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------------------------------------------------#
